

//TODO a(43)
function a43(module, exports, a) {
    var i = a(23), s = a(3), r = a(44), n = a(2), o = a(21), l = a(45), d = function (e) {
        this.adVideo = new r(e);
        var t = "_h5ad_" + Math.floor(Math.random() * +new Date);
        this.h5ad = new l(this, t)
    };
    s.extend(d, i);
    var h = {
        init: function () {
            this.manager.log.pushLog("init ad"), this.playerData = this.manager.playerData, this.manager.register(this.adVideo), this.manager.listener.on(o.PLAY_STATE, function (e, t) {
                "init" != t && "stop" != t || !this.iAd || this.iAd("OnRefreshAd", {
                    curAD: this.curAD,
                    curIndex: this.curIdx
                })
            }, this), this.adPause = new p(this)
        }, getAdParam: function () {
            var e = this.manager.listener.get(o.USER_INFO), t = this.playerData.vinfo, a = {
                pname: this.playerData.pname,
                tplType: this.playerData.tplType,
                cont: this.playerData.config.cont,
                ch: this.manager.pingback.getCH(),
                uid: e ? e.ssouid : null,
                up: this.playerData.vinfo.up,
                ispay: this.playerData.vinfo.ispay,
                ver: this.playerData.playerVersion,
                uuid: this.manager.pingback.getUUID(),
                lc: this.manager.pingback.getLC(),
                islive: "live" == this.playerData.playerType,
                ark: this.playerData.flashVar.ark || "",
                p1: this.playerData.config.p1,
                p2: this.playerData.config.p2,
                p3: "",
                isAlbumPay: this.playerData.vinfo.isAlbumPay,
                tryLookType: this.playerData.tryLookType,
                tryLookTime: this.playerData.tryLookTime,
                liveType: this.playerData.vinfo.liveType,
                vipInfo: e ? e.vipInfoObj : null,
                cid: this.playerData.vinfo.cid,
                Notplayinline: n.Notplayinline,
                isHttps: this.playerData.flashVar.isHttps
            };
            return a = s.merge(a, t, !0), this.manager.log.pushLog("adParam :" + s.JSONTOStr(a)), a
        }, refreshAd: function () {
            this.manager.log.pushLog("refresh ad");
            var e = this.getAdParam();
            this.internalCallback("adEnded", null), this.onADLoaded(e)
        }, destoryAd: function () {
            try {
                this.h5ad.destory()
            } catch (e) {
                console.log(e)
            }
        }, callback: function (e, t) {
            try {
                "getCurrTime" != e && this.manager.log.pushLog("ad callback: " + e + ";data: " + s.JSONTOStr(t))
            } catch (a) {
            }
            try {
                if ("undefined" != typeof this.videoCtrl)return this.videoCtrl.cmd(e, t)
            } catch (a) {
                this.h5ad.requestLock = !1, this.manager.evt.trigger("vjs_adEnded")
            }
        }, internalCallback: function (e, t) {
            this.manager.log.pushLog("ad internalCallback: " + e + ";data: " + s.JSONTOStr(t));
            try {
                switch (e) {
                    case"adEnded":
                        this.h5ad.requestLock = !1, t && t.reason && this.manager.evt.trigger("vjs_adEnded"), this.videoCtrl && this.videoCtrl.removeListener();
                        break;
                    case"login":
                        this.manager.evt.trigger(o.EVENT.PLAYER_CALLBACK, "openLoginDialog")
                }
            } catch (a) {
                this.h5ad.requestLock = !1, this.manager.log.pushLog("ad error: " + e), this.manager.evt.trigger("vjs_adEnded")
            }
        }, onADLoaded: function (e) {
            var t = this.h5ad;
            "undefined" != typeof t && "function" == typeof t.initAD && (this.iAd = t.sendEvent, this.videoCtrl = new c(this), t.initAD(e, this.callback))
        }, play: function () {
        }
    };
    s.merge(d.prototype, h);
    var c = function (e) {
        this.h5ad = e.h5ad, this.adVideo = e.adVideo, this.manager = e.manager, this.internalCallback = function () {
            e.internalCallback.apply(e, arguments)
        }, this.config = e.playerData.config, this.urls = [], this.events = ["ad_error", "ad_play", "ad_playing", "ad_ended", "ad_pause", "ad_timeupdate"], this.removeListener(), this.installListener(), this.iAd = this.h5ad.sendEvent
    };
    c.prototype = {
        cmd: function (e, t) {
            switch (e) {
                case"playAD":
                    this.urls = t, this.manager.playerData.hasAD = 0 != this.urls.length, this.playAD(0);
                    break;
                case"stopAD":
                    this.internalCallback("adEnded", t);
                    break;
                case"resumeAD":
                    this.adVideo.play();
                    break;
                case"pauseAD":
                    this.adVideo.pause();
                    break;
                case"getCurrTime":
                    return this.adVideo.getCurrentTime();
                case"login":
                    this.internalCallback(e);
                    break;
                case"seek":
                    var a = Number(t);
                    if (isNaN(a))return;
                    this.adVideo.seek(a);
                    break;
                case"lanfit":
                    var i = t.toString();
                    return this.manager.lanFit && "function" == typeof this.manager.lanFit.fit && (i = this.manager.lanFit.fit(i)), i
            }
        }, playAD: function (e) {
            this.curIdx = e || 0, this.urls && this.urls.length > e && this.urls[e] ? (this.curAD = this.urls[e], this.adVideo.setSrc(this.curAD.url)) : this.internalCallback("adEnded", {reason: 12})
        }, installListener: function () {
            this.enabled = !0, s.each.call(this, this.events, function (e, t) {
                this.manager.evt.on(t, this.onVideoEvent, this)
            }), this.manager.listener.on(o.USER_INFO, this.onUserInfoChang, this)
        }, removeListener: function () {
            this.enabled && (this.enabled = !1, s.each.call(this, this.events, function (e, t) {
                this.manager.evt.off(t, this.onVideoEvent, this)
            }), this.manager.listener.off(o.USER_INFO, this.onUserInfoChang, this))
        }, onVideoEvent: function (e) {
            switch (e.type) {
                case"ad_play":
                case"ad_playing":
                    this.callAD("AD_PLAY");
                    break;
                case"ad_timeupdate":
                    this.callAD("AD_TimeUpdate");
                    break;
                case"ad_pause":
                    this.playID && clearTimeout(this.playID), this.callAD("AD_PAUSE");
                    break;
                case"ad_ended":
                    this.callAD("AD_ENDED"), this.playAD(++this.curIdx);
                    break;
                case"ad_error":
                    this.callAD("AD_ERROR", {error: 1});
                    try {
                        this.h5ad.collectError("221&" + JSON.stringify(this.curAD))
                    } catch (t) {
                    }
                    this.manager.pingback.sendError(o.ERROR_CODE.ADURL_NOT_SUPPORT), this.manager.log.pushLog("adSrc: " + this.adVideo.getSrc()), this.playAD(++this.curIdx)
            }
        }, onUserInfoChang: function (e, t) {
            this.callAD("loginCb", {level: t ? t.isvip : null, uid: t ? t.ssouid : null})
        }, callAD: function (e, t) {
            try {
                t || (t = {}), s.merge(t, {curAD: this.curAD, curIndex: this.curIdx}), this.iAd.call(this.h5ad, e, t)
            } catch (a) {
            }
        }
    };
    var p = function (e) {
        this.h5ad = e.h5ad, this.manager = e.manager, this.manager.listener.on(o.PLAY_STATE, function (t, a) {
            "play" == a && e.h5ad.closePauseRender(e.h5ad)
        }), this.manager.evt.on("vjs_activePause", function () {
            var t = {onTime: Math.round(1e3 * this.manager.curVideo.getCurrentTime())};
            e.h5ad.getPauseData(t)
        }, this)
    };
    module.exports = d
}

